import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from "path"
import { createHtmlPlugin } from 'vite-plugin-html';
import DefineOptions from 'unplugin-vue-define-options/vite';
import Components from 'unplugin-vue-components/vite'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
export default defineConfig({
  plugins: [vue(),
  createHtmlPlugin({
    inject: {
      data: {
        injectScript: `<script type="module" src="./static.env.config.js"></script>`,
      },
    },
  }),
  DefineOptions(),
  createSvgIconsPlugin({
    // 指定需要缓存的图标文件夹
    iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
    // 指定symbolId格式
    symbolId: 'icon-[name]'
  }),
  Components({})
  ],
  resolve: {
    alias: {
      // 如果报错__dirname找不到，需要安装node,执行npm install @types/node --save-dev
      "@": path.resolve(__dirname, "src"),
    },
  }, css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@import "@/assets/style/reset.scss";`
      }
    }
  },
  server: {
    proxy: {
      "/api": {
        target: "http://www.cacmb.com",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ""),
      },
    },
  },
});